package com.woniuxy.Request;

import com.woniuxy.Bean.User;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @auther linke
 * @create 2021-10-17 0:04
 */
@WebServlet("/requestDemo04")
public class RequestDemo04 extends HttpServlet {
    /**
     * 模拟防盗链
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        String referer = req.getHeader("Referer");
        if (referer != null && referer.equals("http://localhost:8080/web03/login.html"))
            req.getRequestDispatcher("/requestDemo03").forward(req, resp);//请求转发
        else {
            resp.getWriter().write("访问路径错误");
        }
    }

    /**
     * 默认调佣doget方法
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
